package com.stone.design.practice.broadcastreceiver;

import android.content.Intent;
import android.content.IntentFilter;
import android.os.AsyncTask;
import android.os.Bundle;
import android.support.v4.view.ViewPager;
import android.support.v7.app.AppCompatActivity;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;

import com.stone.design.practice.R;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

/**
 * @author Stone
 * @version V1.0
 * @description:
 * @date 7/27/18 3:44 PM
 */
public class BroadcastReceiverActivity extends AppCompatActivity {


    @BindView(R.id.btn_send)
    Button mBtnSend;
    @BindView(R.id.tv_show)
    TextView mTvShow;
    private MyBroadcastReceiver mMyBroadcastReceiver;
    private IntentFilter mInflater;

    private MyTask mAsyncTask;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_broadcast_receiver);
        ButterKnife.bind(this);

        mMyBroadcastReceiver = new MyBroadcastReceiver();
        mInflater = new IntentFilter("com.stone");
        registerReceiver(mMyBroadcastReceiver, mInflater, "com.stone.permission.test",
                null);



    }

    @OnClick({R.id.btn_send, R.id.btn_cancel, R.id.btn_task})
    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.btn_send: {
                Intent intent = new Intent("com.stone");
                sendBroadcast(intent,"com.stone.permission.test");
                break;
            }

            case R.id.btn_cancel: {
                unregisterReceiver(mMyBroadcastReceiver);
            }

            case R.id.btn_task: {
                mAsyncTask = new MyTask();
                mAsyncTask.execute("http://www.baidu.com");
                

                break;
            }
            default:
                break;
        }


    }


    public static final String TAG = "Stone";

    private class MyTask extends AsyncTask<String, Integer, String> {


        @Override
        protected void onPreExecute() {
            Log.e("Stone", "onPreExecute(BroadcastReceiverActivity.java:85)-->>"+1);
            super.onPreExecute();
        }

        @Override
        protected String doInBackground(String... strings) {
            Log.e(TAG, "doInBackground(BroadcastReceiverActivity.java:93)-->>"+2);
            return "ja";
        }

        @Override
        protected void onProgressUpdate(Integer... values) {
            Log.e(TAG, "onProgressUpdate(BroadcastReceiverActivity.java:99)-->>"+"onProgressUpdate");
            super.onProgressUpdate(values);
        }

        @Override
        protected void onPostExecute(String integer) {
            Log.e(TAG, "onPostExecute(BroadcastReceiverActivity.java:104)-->>"+integer);
            super.onPostExecute(integer);
        }
    }



}
